<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>李佳音的作业3</title>
</head>
<body>
<pre>
import math

position = [0,0]
while True:
    s = input()
    if not s:
        break
    if s == "STOP":
        break
    movement = s.split(" ")
    direction = movement[0]
    steps = int(movement[1])
    if direction == "UP":
        position[0]+=steps
    elif direction == "DOWN":
        position[0]-=steps
    elif direction == "LEFT":
        position[1] -= steps
    elif direction == "RIGHT":
        position[1] += steps
    else:
        pass
print(int(round(math.sqrt(position[1]**2+position[0]**2))))
</pre>
</body>
</html>